#version 460
#extension GL_GOOGLE_include_directive : enable
#extension GL_EXT_shader_explicit_arithmetic_types_int64 : require

#include "../../../../core/shader_std.h"
#include "../../../../core/shader_built_in_functions.h"
#include "../../../../core/shader_taster_transform.h"
#include "../../../../core/shader_taster_line.h"




layout(location = 0) in vec3 inPos;
layout(location = 1) in uint inCol;


layout(location=0) out vec4 vColor;
out gl_PerVertex {
	vec4	gl_Position;
	float	gl_PointSize;
};
layout(location=2) out float DepthScale;
layout(location=3) out float Transparency;

//vec3 vs[3] = {vec3(-100,-500,0), vec3(-100,500,0), vec3(500,00,0)};

void main(void) {
	vec4 p = vec4(inPos, 1.0);
	//uint InstanceOffset = gl_BaseInstance;
	uint InstanceOffset = gl_InstanceIndex + drawProp.MatrixOffset;
	//uint InstanceOffset = gl_InstanceIndex;

	gl_PointSize = 3.0;
	S_MeshTranformProp prop = m_LinesProp[drawProp.MeshPropOffset + gl_DrawID];
	mat4 bonesMat_som = mat_Model[InstanceOffset];
	//vec4 pos = mat_ProjecView[0] * vec4(0,0,0,1);
	
	if(prop.m_Color > 0){
		vColor = f_glsl_buildColor(prop.m_Color);
	} else {
		vColor = f_glsl_buildColor(inCol) * prop.m_Intensity;
	}
	DepthScale = prop.m_DepthScale;
	//DepthScale = 1;
	//float d = length(p.xyz - pos.xyz) / 500.0;
	
	if ( f_lineMeshTranform(p, vec3(0), prop, bonesMat_som, inverse(mat3(mat_ProjecView[1])), mat_ProjecView[3][3].xyz) ) {
		gl_Position = mat_ProjecView[0] * p;
		//return;
	}

	
	
	gl_Position = mat_ProjecView[0] * p;

	switch(int(prop.m_Activate)){
		case 1:
			//gl_Position.z += 0.001;
			vec3 z = normalize(inverse(mat3(mat_ProjecView[1])) * vec3(0.0, 0.0, -1.0));
			gl_Position.z += 0.1 / length(gl_Position.xyz - z);
		break;
	}
	
	Transparency = prop.m_Remote;
}


